<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        function getData(url) {
            var p = new Promise((resolve, reject) => {
                // 1.创建xhr对象
                var xhr = new XMLHttpRequest()
                // 2.配置请求和地址
                xhr.open('GET', url)
                // 3. 开始发送请求
                xhr.send()
                // 4.接受结果
                xhr.onreadystatechange = function () {
                    if (xhr.readyState != 4) { return }
                    if (xhr.readyState === 4 && xhr.status === 200) {
                        resolve(xhr.responseText)
                    } else {
                        reject('出错了')
                    }
                }

            })
            return p
        }
        // 保证ajax按照顺序进行
        getData(' http://localhost:3000/data').then((data) => {
            console.log(data)
            return getData(' http://localhost:3000/data1')
        }).then((data) => {
            console.log(data)
            return getData(' http://localhost:3000/data2')
        }).then((data) => {
            console.log(data)
        })


    </script>

</body>

</html>